//
//  PSP2View.m
//  Experss
//
//  Created by 嗯，大葱 on 17/8/11.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "PSP2View.h"
#import "PSPCell.h"

@implementation PSP2View

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5f];
        
    }
    return self;
}

- (void)setDataArary:(NSArray *)dataArary {
    _dataArary = dataArary;
    [self configuV];
}


- (void)configuV {
    if (_tableView) {
        [_tableView removeFromSuperview];
    }
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kView_Width, 60*_dataArary.count) style:(UITableViewStylePlain)];
    
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = kSpNone;
    _tableView.scrollEnabled = NO;
    [self addSubview:_tableView];
    [self.tableView registerNib:[UINib nibWithNibName:@"PSPCell" bundle:nil] forCellReuseIdentifier:@"PSPCell"];
    UIButton *reB = [UIButton buttonWithType:(UIButtonTypeCustom)];
    reB.frame = CGRectMake(0, CGRectGetMaxY(_tableView.frame), kView_Width, kView_Height- CGRectGetHeight(_tableView.frame));
    reB.backgroundColor = [UIColor clearColor];
    [reB addTarget:self action:@selector(handleRemoBtn:) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:reB];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArary.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    PSPCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PSPCell"];
    cell.conLB.text = _dataArary[indexPath.row];
    cell.selectionStyle = kSeNone;
    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if(self.delegate && [self.delegate respondsToSelector:@selector(selePeiSongIndepath2:title:)])
    {
        [self.delegate selePeiSongIndepath2:indexPath title:_dataArary[indexPath.row]];
    }
}

- (void)handleRemoBtn :(UIButton *)sender {
    if(self.delegate && [self.delegate respondsToSelector:@selector(remoPopTableAction2:)])
    {
        [self.delegate remoPopTableAction2:sender];
    }
}





@end
